package br.inf.ufrgs.usixml4desktopl.rendering.javadesktop;

import javax.swing.JFrame;
import javax.swing.UIManager;

import org.jdom.Element;

import br.inf.ufrgs.usixml4desktop.exceptions.ParsingErrorException;
import br.inf.ufrgs.usixml4desktop.exceptions.RenderingErrorException;
import br.inf.ufrgs.usixml4desktop.rendering.UsiXMLElementRenderer;
import br.inf.ufrgs.usixml4desktop.rendering.UsiXMLInterfaceRenderer;
import br.inf.ufrgs.usixml4desktop.rendering.javadesktop.components.UsiXMLJavaDesktopWindowRenderer;

import com.jgoodies.looks.plastic.PlasticXPLookAndFeel;

public class UsiXMLJavaDesktopInterfaceRenderer extends
		UsiXMLInterfaceRenderer {

	private UsiXMLElementRenderer mainWindowRenderer = null;
			
	private JFrame mainWindow = null;
	
	public UsiXMLJavaDesktopInterfaceRenderer() {
		this.mainWindowRenderer = 
			new UsiXMLJavaDesktopWindowRenderer(this);
	}
	
	public void renderInterface(Element cuiModel) 
		throws RenderingErrorException, ParsingErrorException {
		
		 Element window = cuiModel.getChild("window", cuiModel.getNamespace());
         try{
        	 this.mainWindow = (JFrame)this.mainWindowRenderer.renderElement(window);	 
         }catch (ClassCastException e){
        	 throw new RenderingErrorException();
         }
		
		 try {
			 UIManager.setLookAndFeel(new PlasticXPLookAndFeel());
             	    /*"com.jgoodies.looks.windows.WindowsLookAndFeel"
             	    "com.jgoodies.looks.plastic.PlasticLookAndFeel"
             	    "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"
             	    "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"*/ 
         } catch (Exception e) {
        	 e.printStackTrace();
         }
         
         
         this.mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         this.mainWindow.pack();
         this.mainWindow.setVisible(true);
         this.mainWindow.setState(JFrame.MAXIMIZED_BOTH);
         this.mainWindow.toFront();
		
		

	}

}
